package com.elinkway.infinitemovies.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.elinkway.infinitemovies.bean.AlbumHeaderShowBean;
import com.elinkway.infinitemovies.bean.AlbumShowBean;
import com.elinkway.infinitemovies.bean.HzPayload;
import com.elinkway.infinitemovies.bean.IntervalBean;
import com.elinkway.infinitemovies.bean.JumpData;
import com.elinkway.infinitemovies.bean.Lottery;
import com.elinkway.infinitemovies.bean.NewAdDataBean;
import com.elinkway.infinitemovies.bean.PlayData;
import com.elinkway.infinitemovies.bean.RecommendBase;
import com.elinkway.infinitemovies.bean.SDKPayload;
import com.elinkway.infinitemovies.bean.ServerPayload;
import com.elinkway.infinitemovies.bean.TtPayload;
import com.elinkway.infinitemovies.bean.XfPayload;
import com.elinkway.infinitemovies.bean.YzPayload;
import com.elinkway.infinitemovies.bigdata.BigDataApi;
import com.elinkway.infinitemovies.bigdata.RealDataApi;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.ui.activity.ChannelDetailActivity;
import com.elinkway.infinitemovies.ui.activity.SpreadActivity;
import com.elinkway.infinitemovies.ui.activity.TopicDetailActivity;
import com.elinkway.infinitemovies.ui.activity.VideoDetailActivity;
import com.elinkway.infinitemovies.ui.activity.commonwebview.CommonWebViewActivity;
import com.elinkway.infinitemovies.ui.activity.play.PlayActivityLive;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.elinkway.infinitemovies.utils.MoviesUtils;
import com.elinkway.infinitemovies.utils.UIs;
import com.elinkway.infinitemovies.utils.UmengEventPoster;
import com.elinkway.infinitemovies.utils.Utils;
import com.elinkway.infinitemovies.view.GdtNativeAdView;
import com.elinkway.infinitemovies.view.HzPayAdView;
import com.elinkway.infinitemovies.view.ServerNativeAdView;
import com.elinkway.infinitemovies.view.SlideImageView;
import com.elinkway.infinitemovies.view.TtPayAdView;
import com.elinkway.infinitemovies.view.XfPayAdView;
import com.elinkway.infinitemovies.view.YzPayAdView;
import com.le123.ysdq.R;
import com.le123.ysdq.databinding.LayoutAdBannerBinding;
import com.le123.ysdq.databinding.LayoutAlbumFeedBinding;
import com.le123.ysdq.databinding.LayoutAlbumHalfBinding;
import com.le123.ysdq.databinding.LayoutAlbumHeaderBinding;
import com.le123.ysdq.databinding.LayoutAlbumSpecialBinding;
import com.le123.ysdq.databinding.LayoutAlbumThirdBinding;
import com.le123.ysdq.databinding.LayoutIntervalBinding;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Map;

/**
 * Created by xiao on 8/3/17.
 */
public class AlbumShowAdapter extends RecyclerListAdapter {

    public static final String TAG = "AlbumShowAdapter";

    public static final String AD_DATA = "AdData";

    private LayoutInflater mLayoutInflater;
    private Context mContext;
    private static ImageLoader imageloader;
    private static String mBDPageIndex;
    private boolean isRefresh;
    private boolean isNeedResetBannerAd = false;

    public boolean isNeedResetBannerAd() {
        return isNeedResetBannerAd;
    }

    public void setNeedResetBannerAd(boolean needResetBannerAd) {
        isNeedResetBannerAd = needResetBannerAd;
    }

    public boolean isRefresh() {
        return isRefresh;
    }

    public void setRefresh(boolean refresh) {
        isRefresh = refresh;
    }

    public AlbumShowAdapter(final Context mContext, ArrayList pageItemList, String mBDPageIndex) {
        this.mContext = mContext;
        this.mItemList = pageItemList;
        this.mBDPageIndex = mBDPageIndex;
        mLayoutInflater = LayoutInflater.from(mContext);
        imageloader = ImageLoader.getInstance();
    }

    public void setDatas(ArrayList pageItemList){
        this.mItemList = pageItemList;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        if (viewType == MoviesConstant.MODEL_HALF) {
            return new HalfHolder(mLayoutInflater.inflate(R.layout.layout_album_half, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_THIRD) {
            return new ThirdHolder(mLayoutInflater.inflate(R.layout.layout_album_third, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_FEED) {
            return new FeedHolder(mLayoutInflater.inflate(R.layout.layout_album_feed, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_SPECIAL) {
            return new SpecialHolder(mLayoutInflater.inflate(R.layout.layout_album_special, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_HEADER) {
            return new HeaderHolder(mLayoutInflater.inflate(R.layout.layout_album_header, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_FOCUS) {
            return new FocusHolder(mLayoutInflater.inflate(R.layout.layout_home_focus_base, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_FULL) {
            return new HalfHolder(mLayoutInflater.inflate(R.layout.layout_album_half, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_AD) {
            return new AdHolder(mLayoutInflater.inflate(R.layout.layout_ad_banner, viewGroup, false));
        } else if (viewType == MoviesConstant.MODEL_INTERVAL) {
            return new IntervalHolder(mLayoutInflater.inflate(R.layout.layout_interval, viewGroup, false));
        } else {
            return new ThirdHolder(mLayoutInflater.inflate(R.layout.layout_album_third, viewGroup, false));
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HalfHolder) {
            ((HalfHolder) holder).bind((AlbumShowBean) mItemList.get(position), mContext);
        } else if (holder instanceof ThirdHolder) {
            ((ThirdHolder) holder).bind((AlbumShowBean) mItemList.get(position), mContext);
        } else if (holder instanceof FeedHolder) {
            ((FeedHolder) holder).bind((AlbumShowBean) mItemList.get(position), mContext);
        } else if (holder instanceof SpecialHolder) {
            ((SpecialHolder) holder).bind((AlbumShowBean) mItemList.get(position), mContext);
        } else if (holder instanceof HeaderHolder) {
            ((HeaderHolder) holder).bind((AlbumHeaderShowBean) mItemList.get(position), mContext);
        } else if (holder instanceof FocusHolder) {
            ((FocusHolder) holder).bind((ArrayList) mItemList.get(position), isRefresh, mContext);
            isRefresh = false;
        } else if (holder instanceof AdHolder) {
            ((AdHolder) holder).bind((NewAdDataBean) mItemList.get(position), isNeedResetBannerAd, mContext);
            isNeedResetBannerAd = false;
        } else if (holder instanceof IntervalHolder) {
            ((IntervalHolder) holder).bind((IntervalBean) mItemList.get(position), mContext);
        } else {

        }
    }

    @Override
    public int getItemViewType(int position) {
        Object obj = mItemList.get(position);
        if (obj instanceof ArrayList) {
            return MoviesConstant.MODEL_FOCUS;
        } else if (obj instanceof AlbumHeaderShowBean) {
            return MoviesConstant.MODEL_HEADER;
        } else if (obj instanceof AlbumShowBean) {
            AlbumShowBean bean = (AlbumShowBean) obj;
            if (MoviesConstant.MODEL_HALF == bean.getType()) {
                return MoviesConstant.MODEL_HALF;
            } else if (MoviesConstant.MODEL_THIRD == bean.getType()) {
                return MoviesConstant.MODEL_THIRD;
            } else if (MoviesConstant.MODEL_FEED == bean.getType()) {
                return MoviesConstant.MODEL_FEED;
            } else if (MoviesConstant.MODEL_SPECIAL == bean.getType()) {
                return MoviesConstant.MODEL_SPECIAL;
            } else if (MoviesConstant.MODEL_FULL == bean.getType()) {
                return MoviesConstant.MODEL_FULL;
            } else {
                return MoviesConstant.MODEL_THIRD;
            }
        } else if (obj instanceof NewAdDataBean) {
            return MoviesConstant.MODEL_AD;
        } else if (obj instanceof IntervalBean) {
            return MoviesConstant.MODEL_INTERVAL;
        } else {
            return MoviesConstant.MODEL_THIRD;
        }
    }

    public static class HalfHolder extends RecyclerView.ViewHolder {
        private LayoutAlbumHalfBinding mHalfBinding;

        public HalfHolder(View itemView) {
            super(itemView);
            mHalfBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull AlbumShowBean albumShowBean, final Context context) {
            mHalfBinding.setAlbum(albumShowBean);
            imageloader.displayImage(albumShowBean.getPich(), mHalfBinding.recommendGridItemPoster);
            if (TextUtils.isEmpty(albumShowBean.getEposidesInfo())) {
                mHalfBinding.episodeCount.setVisibility(View.GONE);
            } else {
                mHalfBinding.episodeCount.setVisibility(View.VISIBLE);
            }
            if (!TextUtils.isEmpty(albumShowBean.getCornerColor())) {
                mHalfBinding.rightTagTv.setBackgroundColor(Color.parseColor(albumShowBean.getCornerColor()));
            } else {
                mHalfBinding.rightTagTv.setBackgroundResource(R.color.transparent);
            }
            final AlbumShowBean bean = albumShowBean;
            mHalfBinding.albumItemRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    albumJump(bean, context);
                }
            });
        }
    }

    public static class ThirdHolder extends RecyclerView.ViewHolder {
        private LayoutAlbumThirdBinding mThirdBinding;

        public ThirdHolder(View itemView) {
            super(itemView);
            mThirdBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull AlbumShowBean albumShowBean, final Context context) {
            mThirdBinding.setAlbum(albumShowBean);
            imageloader.displayImage(albumShowBean.getPic(), mThirdBinding.recommendGridItemPoster);
            if (TextUtils.isEmpty(albumShowBean.getEposidesInfo())) {
                mThirdBinding.episodeCount.setVisibility(View.GONE);
            } else {
                mThirdBinding.episodeCount.setVisibility(View.VISIBLE);
            }
            if (!TextUtils.isEmpty(albumShowBean.getCornerColor())) {
                mThirdBinding.rightTagTv.setBackgroundColor(Color.parseColor(albumShowBean.getCornerColor()));
            } else {
                mThirdBinding.rightTagTv.setBackgroundResource(R.color.transparent);
            }
            final AlbumShowBean bean = albumShowBean;
            mThirdBinding.albumItemRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    albumJump(bean, context);
                }
            });
        }
    }

    public static class FeedHolder extends RecyclerView.ViewHolder {
        private LayoutAlbumFeedBinding mFeedBinding;

        public FeedHolder(View itemView) {
            super(itemView);
            mFeedBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull AlbumShowBean albumShowBean, final Context context) {
            mFeedBinding.setAlbum(albumShowBean);
            imageloader.displayImage(albumShowBean.getPich(), mFeedBinding.recommendGridItemPoster);
            if (TextUtils.isEmpty(albumShowBean.getEposidesInfo())) {
                mFeedBinding.episodeCount.setVisibility(View.GONE);
            } else {
                mFeedBinding.episodeCount.setVisibility(View.VISIBLE);
            }
            final AlbumShowBean bean = albumShowBean;
            mFeedBinding.albumItemRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    albumJump(bean, context);
                }
            });
            if (MoviesUtils.isProductCjsp()){
                mFeedBinding.divideGragView.setVisibility(View.VISIBLE);
            }
        }
    }

    public static class SpecialHolder extends RecyclerView.ViewHolder {
        private LayoutAlbumSpecialBinding mSpecialBinding;

        public SpecialHolder(View itemView) {
            super(itemView);
            mSpecialBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull final AlbumShowBean albumShowBean, final Context context) {
            mSpecialBinding.setAlbum(albumShowBean);
            imageloader.displayImage(albumShowBean.getPich(), mSpecialBinding.recommendGridItemPoster);
            mSpecialBinding.albumItemRl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    albumJump(albumShowBean, context);
                }
            });
            if (MoviesUtils.isProductCjsp()){
                mSpecialBinding.divideGragView.setVisibility(View.VISIBLE);
            }
        }
    }

    public static class HeaderHolder extends RecyclerView.ViewHolder {
        private LayoutAlbumHeaderBinding mHeaderBinding;

        public HeaderHolder(View itemView) {
            super(itemView);
            mHeaderBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull final AlbumHeaderShowBean headerBean, final Context context) {
            mHeaderBinding.setHeader(headerBean);
            if (TextUtils.isEmpty(headerBean.getRecname())) {
                mHeaderBinding.modelHeaderRl.setVisibility(View.GONE);
                mHeaderBinding.headerTitleTv.setVisibility(View.GONE);
                mHeaderBinding.modelHeaderRl.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
            } else {
                mHeaderBinding.modelHeaderRl.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, UIs.dipToPx(45)));
                mHeaderBinding.headerTitleTv.setVisibility(View.VISIBLE);
                mHeaderBinding.modelHeaderRl.setVisibility(View.VISIBLE);
            }
            if (TextUtils.isEmpty(headerBean.getVt()) || MoviesConstant.STYLE_FEED.equals(headerBean.getStyle())) {
                mHeaderBinding.moreTv.setVisibility(View.GONE);
            } else {
                mHeaderBinding.moreTv.setVisibility(View.VISIBLE);
                mHeaderBinding.moreTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        JumpData jumpdata = new JumpData();
                        jumpdata.setVt(headerBean.getVt());
                        jumpdata.setAreaid(headerBean.getAreaid());
                        jumpdata.setCategoryid(headerBean.getCategoryid());
                        jumpdata.setSort(headerBean.getSort());
                        Intent jumpIntent = new Intent(context,
                                ChannelDetailActivity.class);
                        Bundle bundle = new Bundle();
                        bundle.putSerializable(Utils.CHANNEL_DTAT, jumpdata);
                        jumpIntent.putExtras(bundle);
                        context.startActivity(jumpIntent);
                    }
                });
            }
        }
    }

    public static class FocusHolder extends RecyclerView.ViewHolder {
        private RelativeLayout mFocusBase;
        private View mFocusUp;
        private SlideImageView sliderIv;
        private View divideGragView;

        public FocusHolder(View itemView) {
            super(itemView);
            mFocusBase = (RelativeLayout) itemView;
        }

        public void bind(@NonNull final ArrayList list, final boolean isRefresh, final Context context) {
            if(mFocusUp == null || isRefresh){
                mFocusBase.removeAllViews();
                mFocusUp = View.inflate(context, R.layout.layout_home_focus, null);
                sliderIv = (SlideImageView) mFocusUp.findViewById(R.id.slider_iv);
                divideGragView = mFocusUp.findViewById(R.id.divide_grag_view);
                mFocusBase.addView(mFocusUp);
            }
            sliderIv.load((Activity) context, list, imageloader, mBDPageIndex, new SlideImageView.OnSliderListener() {
                @Override
                public void onSliderClick(Object object) {
                    if (object instanceof RecommendBase) {
                        try {
                            focusJump((RecommendBase) object, context);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                }

                @Override
                public String getImageUrl(Object object) {
                    return null;
                }
            });
            if (MoviesUtils.isProductCjsp()){
                divideGragView.setVisibility(View.VISIBLE);
            }
        }
    }

    public static class IntervalHolder extends RecyclerView.ViewHolder {
        private LayoutIntervalBinding mIntervalBinding;

        public IntervalHolder(View itemView) {
            super(itemView);
            mIntervalBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull final IntervalBean interval, final Context context) {

        }
    }

    public static class AdHolder extends RecyclerView.ViewHolder {
        private LayoutAdBannerBinding mAdBinding;
        //避免重复加载问题
        private ServerNativeAdView serverAd;
        private GdtNativeAdView gdtAd;
        private HzPayAdView hzAdView;
        private YzPayAdView yzAdView;
        private XfPayAdView xfAdView;
        private TtPayAdView ttPayAdView;

        public AdHolder(View itemView) {
            super(itemView);
            mAdBinding = DataBindingUtil.bind(itemView);
        }

        public void bind(@NonNull final NewAdDataBean adBean, final boolean isNeedResetBannerAd, final Context context) {
            if(isNeedResetBannerAd){
                serverAd = null;
                gdtAd = null;
                hzAdView = null;
                yzAdView = null;
                xfAdView = null;
                ttPayAdView = null;
                mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
            }
            if (Utils.SERVER_AD.equals(adBean.provider)) {
                if(serverAd == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    final ServerPayload serverPayload = (ServerPayload) adBean.payload;
                    serverAd = new ServerNativeAdView((Activity) context, mAdBinding.linearLayoutRecommend, "homebanner");
                    serverAd.setServerAd(serverPayload, MoviesHttpApi.HOME_BANNER);
                }
            }  else if (Utils.GDT_AD.equalsIgnoreCase(adBean.provider)) {
                if(gdtAd == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, UIs.getScreenWidth()/2);
                    mAdBinding.linearLayoutRecommend.findViewById(R.id.home_banner_ad).setLayoutParams(params);
                    gdtAd = new GdtNativeAdView((Activity) context, "banner", mAdBinding.linearLayoutRecommend, "homebanner");
                    gdtAd.loadAD(((SDKPayload)adBean.payload).adId);
                }
            } else if (Utils.HZ_AD.equals(adBean.provider)) {
                if(hzAdView == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    hzAdView = new HzPayAdView((Activity) context, mAdBinding.linearLayoutRecommend, "homebanner");
                    hzAdView.setHzAd(((HzPayload)adBean.payload).ad);
                }
            } else if (Utils.YZ_AD.equals(adBean.provider)) {
                if(yzAdView == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    yzAdView = new YzPayAdView((Activity) context, mAdBinding.linearLayoutRecommend, "homebanner");
                    yzAdView.setYzAd(((YzPayload)adBean.payload).ad);
                }
            } else if (Utils.XF_AD.equals(adBean.provider)) {
                if(xfAdView == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    xfAdView = new XfPayAdView((Activity) context, mAdBinding.linearLayoutRecommend, "homebanner");
                    xfAdView.setXfAd(((XfPayload)adBean.payload).ad);
                }
            } else if (Utils.TT_AD.equals(adBean.provider)) {
                if(ttPayAdView == null){
                    mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                    ttPayAdView = new TtPayAdView((Activity) context, mAdBinding.linearLayoutRecommend, "homebanner");
                    ttPayAdView.setTtAd(((TtPayload)adBean.payload).ad);
                }
            }else {
                mAdBinding.linearLayoutRecommend.setLayoutParams(new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));
            }
        }
    }

    //焦点图的跳转
    public static void focusJump(RecommendBase recommendBase, Context mContext) {
        // 获取当前展示类型
        String display = recommendBase.getDisplay();
        Intent intent = new Intent();
        JumpData jumpData = new JumpData();
        jumpData.setName(recommendBase.getName());
        Bundle jumpbundle = new Bundle();
        String key = Utils.CHANNEL_DTAT;
        Serializable value = jumpData;

        UmengEventPoster.postFocusClick(recommendBase.getCurrentShowIndex() + 1, recommendBase.getDisplay(), recommendBase.getName());

        if (Utils.ALBUM.equals(display)) {
            // 当前是专辑
            jumpData.setAid(recommendBase.getAid());
            jumpData.setName(recommendBase.getName());
            intent.setClass(mContext, VideoDetailActivity.class);
            jumpbundle.putSerializable(Utils.ALBUM_DATA, jumpData);

            Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=focus", "0", "-", recommendBase.getAid(), "-");
            dataMap.put("rank", recommendBase.getCurrentShowIndex() + 1 + "");
            dataMap.put("cur_url", mBDPageIndex);
            BigDataApi.bigDataCommonReport(dataMap, mContext);
        } else if (Utils.THEME.equals(display)) {
            // 当前是专题
            jumpData.setThemeid(recommendBase.getThemeid());
            intent.setClass(mContext, TopicDetailActivity.class);
            jumpbundle.putSerializable(Utils.THEME_DATA, jumpData);

            Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=focus", "0", "-", "-", "-");
            dataMap.put("rank", recommendBase.getCurrentShowIndex() + 1 + "");
            dataMap.put("zid", recommendBase.getThemeid());
            dataMap.put("cur_url", mBDPageIndex);
            BigDataApi.bigDataCommonReport(dataMap, mContext);

        } else if (Utils.LINK.equals(display)) {
            // 当前是跳转链接
            jumpData.setPlayUrl(recommendBase.getPlayurl());
            jumpData.setShareTitle(recommendBase.getShareTitle());
            jumpData.setSharePic(recommendBase.getSharePic());
            jumpData.setShareDesc(recommendBase.getShareDesc());
            intent.setClass(mContext, CommonWebViewActivity.class);
            intent.putExtra("isNeedShare", true);
            jumpbundle.putSerializable(Utils.CHANNEL_DTAT, jumpData);

            Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=focus", "0", "-", recommendBase.getPlayurl(), "-");
            dataMap.put("rank", recommendBase.getCurrentShowIndex() + 1 + "");
            dataMap.put("cur_url", mBDPageIndex);
            BigDataApi.bigDataCommonReport(dataMap, mContext);
        } else if (Utils.ACTIVITY.equals(display)) {
            // 活动
            Lottery l = new Lottery();
            l.setUrl(recommendBase.getPlayurl());
            l.setId(99);
            SpreadActivity.launch(mContext, l);
            return;
        } else if (Utils.LIVE.equals(display)) {
            // 跳转到直播页面
            intent.setClass(mContext, PlayActivityLive.class);
            PlayData playdata = new PlayData();
            playdata.setmViewName(recommendBase.getName());
            playdata.setLiveStreams(recommendBase.getStreams());
            key = Utils.PLAY_DATA;
            value = playdata;
        } else {
            return;
        }
        jumpbundle.putSerializable(key, value);
        intent.putExtras(jumpbundle);
        mContext.startActivity(intent);
    }

    public static void albumJump(AlbumShowBean albumShowBean, Context mContext) {
        // 获取当前展示类型
        try {
            String display = albumShowBean.getDisplay();
            if (Utils.ALBUM.equals(display)) {
                // 当前是专辑
                Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=" + albumShowBean.getRecname(), "0", "-", albumShowBean.getAid(), "-");
                dataMap.put("rank", albumShowBean.getCurrentShowIndex() + 1 + "");
                dataMap.put("cur_url", mBDPageIndex);
                dataMap.put("reid", albumShowBean.getReid());
                dataMap.put("bucket", albumShowBean.getBucket());
                BigDataApi.bigDataCommonReport(dataMap, mContext);

                RealDataApi.RealDataClickReport(albumShowBean.getReid(), "", albumShowBean.getAid(), albumShowBean.getCategoryname(),albumShowBean.getBucket());

                VideoDetailActivity.launch((Activity) mContext,
                        albumShowBean.getAid(), albumShowBean.getVt(), albumShowBean.getName(), "", albumShowBean.getThemeid(), "", "0",albumShowBean.getReid(),albumShowBean.getBucket());

            } else if (Utils.LINK.equals(display)) {
                // 当前是跳转链接
                Intent intent = new Intent();
                JumpData jumpData = new JumpData();
                jumpData.setName(albumShowBean.getName());
                jumpData.setPlayUrl(albumShowBean.getPlayurl());

                String key = Utils.CHANNEL_DTAT;
                Serializable value = jumpData;

                Bundle jumpbundle = new Bundle();
                jumpbundle.putSerializable(Utils.CHANNEL_DTAT, jumpData);
                jumpbundle.putSerializable(key, value);

                intent.putExtras(jumpbundle);
                intent.setClass(mContext, CommonWebViewActivity.class);

                Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=" + albumShowBean.getRecname(), "0", "-", "", "");
                dataMap.put("rank", albumShowBean.getCurrentShowIndex() + 1 + "");
                dataMap.put("cur_url", mBDPageIndex);
                BigDataApi.bigDataCommonReport(dataMap, mContext);

                mContext.startActivity(intent);

            } else if (Utils.THEME.equals(display)) {
                // 当前是专题
                Intent intent = new Intent();
                JumpData jumpData = new JumpData();
                jumpData.setName(albumShowBean.getName());
                jumpData.setThemeid(albumShowBean.getThemeid());

                String key = Utils.CHANNEL_DTAT;
                Serializable value = jumpData;

                Bundle jumpbundle = new Bundle();
                jumpbundle.putSerializable(Utils.THEME_DATA, jumpData);
                jumpbundle.putSerializable(key, value);

                intent.putExtras(jumpbundle);
                intent.setClass(mContext, TopicDetailActivity.class);

                Map<String, String> dataMap = BigDataApi.createDataMap("0", "recnum=" + albumShowBean.getRecname(), "0", "-", "", albumShowBean.getThemeid());
                dataMap.put("rank", albumShowBean.getCurrentShowIndex() + 1 + "");
                dataMap.put("cur_url", mBDPageIndex);
                BigDataApi.bigDataCommonReport(dataMap, mContext);

                mContext.startActivity(intent);
            }
            UmengEventPoster.postRecomClick(albumShowBean.getCurrentShowIndex() + 1, albumShowBean.getRecname(),
                    albumShowBean.getName());
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

